#ifndef _YEP_SCENETEST_KEYBOARD_HANDLER_TEST
#define _YEP_SCENETEST_KEYBOARD_HANDLER_TEST

#include "common.hpp"
#include "framework/Entity.hpp"
#include "framework/KeyboardHandler.hpp"
#include "framework/KeyboardEvent.hpp"
#include "framework/DrawHandler.hpp"

namespace yep
{
/**
 * @brief Tests the keyboard
 **/
class KeyboardHandlerTest: public Entity, public KeyboardHandler, public DrawHandler
{
public:
    void evCreate( Event &event )
    {
        Scene2d &scene( event.getScene() );
        scene.handleDraw( *this );
        scene.handleKeyboard( *this );
    }

    void evDestroy( Event &event )
    {
        Scene2d &scene( event.getScene() );
        scene.unhandleDraw( *this );
        scene.unhandleKeyboard( *this );
        delete this;
    }

    double getDepth()
    {
        return 0;
    }

    Vector2 getTopLeft()
    {
        return Vector2::MIN;
    }

    Vector2 getBottomRight()
    {
        return Vector2::MAX;
    }

    const set<pair<SDLKey, SDLKey> > &getKeySet()
    {
        static set<pair<SDLKey, SDLKey> > keys;

        if( keys.size() == 0)
            addInterval( keys, SDLK_FIRST, SDLK_LAST );

        return keys;
    }

    void evKeyDown( KeyboardEvent &event )
    {
        _lastDown = event.getKey();
    }

    void evKeyUp( KeyboardEvent &event )
    {
        _lastUp = event.getKey();
    }

    void evKeyPressed( KeyboardEvent &event )
    {
        _lastPressed = event.getKey();
    }

    void evDraw( DrawEvent &event )
    {
        Screen &screen( event.getScreen() );
        stringstream stream;
        stream << "Last Down   : " << SDL_GetKeyName(_lastDown);
        screen.drawText( {0, 240}, Color::LIGHT_GRAY, stream.str() );
        stream.str( "" );
        stream << "Last Up     : " << SDL_GetKeyName(_lastUp);
        screen.drawText( {0, 248}, Color::LIGHT_GRAY, stream.str() );
        stream.str( "" );
        stream << "Last Pressed: " << SDL_GetKeyName(_lastPressed);
        screen.drawText( {0, 256}, Color::LIGHT_GRAY, stream.str() );
        stream.str( "" );
    }

private:
    SDLKey _lastPressed, _lastDown, _lastUp;
};

}

#endif // _YEP_SCENETEST_KEYBOARD_HANDLER_TEST

